package com.suql.networktools.net.model

import com.suql.networktools.RetrofitManage
import com.suql.networktools.bean.TResponse
import com.suql.networktools.bean.UserInfo
import com.suql.networktools.net.DataListener
import com.suql.networktools.net.RxHelper
import com.suql.networktools.net.contract.LoginContract

import io.reactivex.Observable
import io.reactivex.functions.Consumer

/**
 * @ClassName: LoginModel
 * @Dscription: 登陆Model
 * @Author: su qinglin
 * @Date: 2018/7/26 16:02
 */
class LoginModel : LoginContract.IModel {

    override fun login(userName: String, password: String, listener: DataListener<TResponse<UserInfo>>) {

        val observable = RetrofitManage.instance.userService!!.login(userName, password)
        RxHelper.instance.sendRequest(TAG, observable, Consumer { userInfoTResponse -> listener.onResponse(userInfoTResponse) }, Consumer { throwable -> listener.onError(throwable) })
    }

    override fun unSubscribeTask() {

        RxHelper.instance.unSubscribeTask(TAG)
    }

    companion object {

        private val TAG = LoginModel::class.java.simpleName
    }
}
